package com.dudetest.data.objectify.subclassed;

import com.dudetest.data.DAOVersion;
import com.dudetest.data.objectify.DAOBase;
import com.dudetest.dude.DudeA;
import com.dudetest.dude.DudeAB;
import com.googlecode.objectify.ObjectifyOpts;
import com.googlecode.objectify.ObjectifyService;


public class DAOObjectifySubclassed extends DAOBase{
	
	static {
		ObjectifyService.register(DudeSubclassed.class);
		ObjectifyService.register(DudeASubclassed.class);
		ObjectifyService.register(DudeABSubclassed.class);
	}

	public DAOObjectifySubclassed(){
		super();
	}

	public DAOObjectifySubclassed(boolean transactional){
		super(transactional);
	}

	public DAOObjectifySubclassed(ObjectifyOpts opts){
		super(opts);
	}
	
	@Override
	public DudeA getOrCreateDudeA(long id){
		DudeA d = null;
		if((d = this.getDudeA(id)) == null){
			d = new DudeASubclassed(id);
			ofy().put(d);
			log.info("Create and store new DudeA : "+d);
		}else{
			log.info("Load DudeA : "+d);
		}
		return d;
	}
	
	@Override
	public DudeAB getOrCreateDudeAB(long id){
		DudeAB d = null;
		if((d = this.getDudeAB(id)) == null){
			d = new DudeABSubclassed(id);
			ofy().put(d);
			log.info("Create and store new DudeAB : "+d);
		}else{
			log.info("Load DudeAB : "+d);
		}
		return d;
	}

	@Override
	public DudeA getDudeA(long id) {
		return ofy().find(DudeASubclassed.class,id);
	}

	@Override
	public DudeAB getDudeAB(long id) {
		return ofy().find(DudeABSubclassed.class,id);
	}

	@Override
	public DAOVersion getVersion() {
		return DAOVersion.SUBCLASSED;
	}
	
}
